import request from '../utils/request'

export const tagApi = {
  // 创建标签
  create(data) {
    const userInfo = JSON.parse(localStorage.getItem('userInfo') || '{}')
    return request({
      url: '/tag/create',
      method: 'post',
      data: {
        ...data,
        userId: userInfo.id
      }
    })
  },

  // 批量创建标签
  batchCreate(data) {
    return request({
      url: '/tag/batch/create',
      method: 'post',
      data
    })
  },

  // 更新标签
  update(data) {
    const userInfo = JSON.parse(localStorage.getItem('userInfo') || '{}')
    return request({
      url: '/tag/update',
      method: 'post',
      data: {
        ...data,
        userId: userInfo.id
      }
    })
  },

  // 删除标签
  delete(params) {
    const userInfo = JSON.parse(localStorage.getItem('userInfo') || '{}')
    return request({
      url: '/tag/delete',
      method: 'post',
      params: {
        ...params,
        userId: userInfo.id
      }
    })
  },

  // 批量删除标签
  batchDelete(data) {
    return request({
      url: '/tag/batch/delete',
      method: 'post',
      data
    })
  },

  // 获取标签列表
  list(params) {
    return request({
      url: '/tag/list',
      method: 'get',
      params
    })
  },

  // 分页获取标签列表
  page(params) {
    const userInfo = JSON.parse(localStorage.getItem('userInfo') || '{}')
    return request({
      url: '/tag/page',
      method: 'get',
      params: {
        ...params,
        userId: userInfo.id
      }
    })
  },

  // 搜索标签
  search(params) {
    return request({
      url: '/tag/search',
      method: 'get',
      params
    })
  },

  // 导入标签
  import(data) {
    const userInfo = JSON.parse(localStorage.getItem('userInfo') || '{}')
    return request({
      url: '/tag/import',
      method: 'post',
      data: {
        ...data,
        userId: userInfo.id
      }
    })
  },

  // 导出标签
  export(params) {
    const userInfo = JSON.parse(localStorage.getItem('userInfo') || '{}')
    return request({
      url: '/tag/export',
      method: 'get',
      params: {
        ...params,
        userId: userInfo.id
      },
      responseType: 'blob'
    })
  },

  // Excel导入标签
  excelImport(data) {
    const formData = new FormData()
    formData.append('file', data.file)
    formData.append('userId', data.userId)
    
    return request({
      url: '/tag/excel/import',
      method: 'post',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },

  // Excel导出标签
  excelExport(params) {
    return request({
      url: '/tag/excel/export',
      method: 'get',
      params,
      responseType: 'blob'
    })
  }
} 